﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.Dynamics.BusinessConnectorNet;

namespace pistoletyAx
{
    class Model
    {
        Axapta ax = new Axapta();

        internal bool CkeckPermissionAx(string login, string pass)
        {
            ax.Logon("", "", "", "");
            AxaptaObject axObject = ax.CreateAxaptaObject("Object");
            axObject = (AxaptaObject)ax.CallStaticClassMethod("PistoletyAx", "CheckPermissions", login, pass);
            return Convert.ToBoolean(axObject);
        }

        internal ArrayList GetDocumentFromAx()
        {
            AxaptaContainer axContainer;
            axContainer = (AxaptaContainer)ax.CallStaticClassMethod("PistoletyAx", "GetDokumentAx");
            ArrayList dokumenty = new ArrayList();
            for (int i = 1; i <= axContainer.Count; i++)
            {
                dokumenty.Add(axContainer.get_Item(1).ToString());
            }
            return dokumenty;
        }

        internal object GetMagazynierzyFromAx()
        {
            AxaptaContainer axContainer;
            axContainer = (AxaptaContainer)ax.CallStaticClassMethod("PistoletyAx", "GetMagazynierzyAx");
            ArrayList magazynierzy = new ArrayList(2);
            for (int i = 1; i <= axContainer.Count; i++)
            {
                magazynierzy.Add((object)axContainer.get_Item(0).ToString());
            }
            return magazynierzy;
        }

        internal Kontener GetDocumentPositionsAx(int document)
        {
            AxaptaContainer axContainer;
            axContainer = (AxaptaContainer)ax.CallStaticClassMethod("PistoletyAx", "GetMagazynierzyAx");
            Kontener docPositions = new Kontener();
            for (int i = 1; i <= axContainer.Count; i++)
            {
                if (i == 1)
                {
                    docPositions.tablica1 = (ArrayList)axContainer.get_Item(i);
                }
                if (i == 2)
                {
                    docPositions.tablica2 = (ArrayList)axContainer.get_Item(i);
                }
                if (i == 3)
                {
                    docPositions.nrListWys = (string)axContainer.get_Item(i);
                }
                if (i == 4)
                {
                    docPositions.iloscWszystk = (int)axContainer.get_Item(i);
                }
                if (i == 5)
                {
                    docPositions.doZeskanowania = (int)axContainer.get_Item(i);
                }
            }
            return docPositions;
        }

        internal object GetZeskanowanaPozycjaAx(string ean)
        {
            AxaptaContainer axContainer;
            axContainer = (AxaptaContainer)ax.CallStaticClassMethod("PistoletyAx", "GetMagazynierzyAx");
            Kontener position = new Kontener();
            for (int i = 1; i <= axContainer.Count; i++)
            {

                position.Add(axContainer.get_Item(1).ToString());
            }
            return position;
        }
    }
    internal class Kontener
    {
        public ArrayList tablica1 { get; set; }
        public ArrayList tablica2 { get; set; }
        public string nrListWys { get; set; }
        public int iloscWszystk { get; set; }
        public int doZeskanowania { get; set; }
        internal void Add(ArrayList tablica1, ArrayList tablica2, string nrListWys, int iloscWszystkich, int doZeskanowania)
        {
            this.tablica1 = tablica1;
            this.tablica2 = tablica2;
            this.nrListWys = nrListWys;
            this.iloscWszystk = iloscWszystkich;
            this.doZeskanowania = doZeskanowania;
        }
    }
}
